<!DOCTYPE html>
<html>
<head>
<include file="Public:meta"/>
<script type="text/javascript" src="{$_RPath}Public/lib/keditor-4-1-10/kindeditor-all-min.js"></script>
<script type="text/javascript">
 var editor;
  KindEditor.ready(function (K) {
	  editor = K.create('textarea[name="content"]', {
		  allowFileManager: true,
		  resizeType: 1,
		  allowPreviewEmoticons: false,
		  items: [
			 'source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			 'insertunorderedlist', '|', 'emoticons', 'image','flash', 'media', 'link']
	 });
 });
</script>
</head>
<body>

<table id="dg" title="文章内容列表" class="easyui-datagrid" 
        url="{:U('Content/articleList')}?act=ajax"
        toolbar="#tb" pagination="true"
        rownumbers="true" fitColumns="true" fit="true" singleSelect="true" striped="true" style="width:100%;">
    <thead>
        <tr>
            <th field="title" width="38%">文章标题</th>
            <th width="15%" field="category"  align="center">所属分类</th>
            <th width="10%" field="show_index"  align="center" data-options="formatter:function(val,row){ return val == 1 ? '是':'否'}" >推荐PC首页</th>
            <th width="6%" field="hits"  align="center">点击量</th>
            <th field="add_time" width="13%" align="center">添加时间</th>
            <th data-options="field:'action',width:15,align:'center',formatter:actionFun" >操作</th>
        </tr>
    </thead>
</table>
 <div id="tb" style="padding:2px 5px;">
 	所属分类：
    <input name="search_category" id="search_category" class="easyui-combotree" data-options="url:'{:U('Content/getCategoryNode')}'" style="width:150px;"/>
    关键字: <input class="easyui-textbox" id="searchWord" style="width:110px">
    <a href="javascript:void(0);" onClick="searchItem()" class="easyui-linkbutton" iconCls="icon-search">检索</a>
</div>
    
<div id="dlg" class="easyui-dialog" style="width:800px;height:540px;"
        closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" novalidate enctype="multipart/form-data">
    <table style="width:100%; margin-top:20px;" class="form-table">
    	<tr>
        	<td style="width:30%;border-color: #ccc; background:#dcdcdc; border-width: 1px 0 1px 0;text-align:right;">文章标题</td>
            <td style="border-color: #ccc; border-width: 1px 0 1px 0;"><input name="title" class="easyui-textbox" required style="width:100%"/></td>
        </tr>
        <tr>
        	<td style="width:30%; border-color: #ccc; background:#dcdcdc; text-align:right;">推荐到首页</td>
            <td><input type="checkbox" name="show_index" value="1" style="display:inline;"/>推荐到PC首页显示</td>
        </tr>
        <tr>
        	<td style="width:30%; border-color: #ccc; background:#dcdcdc; text-align:right;">所属分类</td>
            <td><input name="category_id" class="easyui-combotree" data-options="url:'{:U('Content/getCategoryNode')}',required:true,validType:'validnode'" style="width:100%"/></td>
        </tr>
 		<tr>
        	<td style="width:30%;border-color: #ccc; background:#dcdcdc; border-width: 1px 0 1px 0;text-align:right;">封面图片</td>
            <td style="border-color: #ccc; border-width: 1px 0 1px 0;"><input name="img" class="easyui-filebox"  style="width:100%" buttonText="选择封面图片[推荐960×640、640×400像素]"/></td>
        </tr>
        <tr>
        	<td style="width:30%; border-color: #ccc; background:#dcdcdc; text-align:right;">文章内容</td>
            <td><textarea name="content"  style="width:650px; height:300px;visibility: hidden;"></textarea></td>
        </tr>
    </table>
    <input type="hidden" name="article_id" />
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveItem()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>
<script type="text/javascript">
	
	$.extend($.fn.validatebox.defaults.rules, {
		validnode: {
			validator: function(value,param){
				return value == '首页' ? false : true;
			},
			message: '请选择有效的文章分类！'
		}
	});
	
	var dealEntity = "文章";							//操作主题
	var doUrl = "{:U('Content/articleSave')}";		//保存链接
	var delUrl = "{:U('Content/articleDel')}";		//删除链接
	
	function initOther(row){
		if(arguments.length > 0){
			editor.html(row.content);
		}
		else{
			editor.sync();
		}
	}
	
	//获取查询参数
	function getParams(){
		var searchWord = $("#searchWord").val();
		var category_id = $("#search_category").combobox('getValue');
		var params = {searchWord:searchWord,category_id:category_id};
		return params; 
	}
	
	function actionFun(val,row,rowIndex){
		var btnStr = '<a href="javascript:void(0)" onclick="doItem('+row.article_id+',1,'+rowIndex+')">生成二维码</a> | '
			+'<a href="javascript:void(0)" onclick="doItem('+row.article_id+',2,'+rowIndex+')">编辑</a> | '
			+'<a href="javascript:void(0)" onclick="delArticle('+rowIndex+','+row.article_id+')">删除</a>';
		return btnStr;
	}	
	
	function doItem(pkid,gid,rindex){
		if(gid == 1){		//生成二维码
			var jumpUrl = "{:U('QRCode/makeQRCodeForUrl')}?node="+pkid+"&type=article";
			window.parent.addTab("生成二维码", jumpUrl);
		}else{
			var dg = $("#dg");
			dg.datagrid('selectRow',rindex);
			editItem();
		}
	}
	function delArticle(index,pkid){
		$("#dg").datagrid('selectRow',index);
		delItem();
	}
	
</script>
<script type="text/javascript" src="{$_BESrcPath}js/commlib.js?v={$srcVer}"></script>
</body>
</html>